<?php
namespace app\common\validate;
use think\Validate;
use think\Request;
class Dynamic extends Validate{
    protected $rule =   [
        // 'username'  => 'require|unique:member',
        // 'password' => 'require|min:6',
        // 'repassword'=>'require|confirm:password',
        // 'phone'   => 'require|unique:member|number|length:11',
        // 'code' => 'require|checkCode',
        // 'nickname' => 'require|max:30',
        // 'birthday' => 'require',
        // 'email' => 'require|email',
        // 'gender' => 'require',
    ];

    protected $message  =   [
        'username.require' => '用户名不为空',
        'username.max' => '用户名长度最多20位',
        'phone.number'   => '手机号必须是数字',
        'phone.length'  => '手机号格式错误',
        'phone.unique'  => '手机号已被注册',
        'password.require' => '密码不能为空',
        'password.min' => '密码长度至少6位',
        // 'code' => '验证码必须填写！',
        'repassword.require' => '确认密码不能为空',
        'repassword.confirm' => '两次输入密码不相同',
        'nickname.require' => '昵称不能为空',
        'nickname.max' => '昵称长度最多20位',
        'birthday.require' => '生日不能为空',
        'email' =>  '邮箱格式错误',
        'gender.require' => '性别不能为空',
    ];

    protected $scene = [
        'add' => ['phone', 'username', 'password'],
        'login'  =>  ['phone'=>'require','password'],
        // 'edit' => ['nickname', 'username', 'birthday', 'email', 'gender'],
        'edit_pwd' => ['password', 'repassword'],
    ];
    
    protected function checkCode($value){
        $code = Request::instance()->session('code');
        if($code != $value){
            return '验证码输入错误';
        }
        else{
            return true;
        }
    }
}